<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8" import="java.util.*,com.model.*"%>
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title></title>
		<!-- 包含头部信息用于适应不同设备 -->
    	<meta name="viewport" content="width=device-width, initial-scale=1">
		<link rel="stylesheet" href="bootstrap-3.3.7/css/bootstrap.min.css" />
		<script type="text/javascript" src="js/jquery-2.2.3.min.js" ></script>
		<script type="text/javascript" src="bootstrap-3.3.7/js/bootstrap.min.js" ></script>
	</head>
	<body>
		<div class="container">
			
			<%@include file="header.jsp" %>
			
			<div class="row" >
				
				<div class="col-md-12" style="min-height: 500px;">
					<a href="student?action=addStudent" class="btn btn-info" style="margin-bottom: 10px;">新增学生信息</a>
					<table class="table table-bordered">
						<thead>
							<tr>
								<th>学号</th>
								<th>姓名</th>
								<th>年龄</th>
								<th>性别</th>
								<th>联系方式</th>
								<th>学校</th>
								<th>年级</th>
								<th>专业</th>
								<th>操作</th>
							</tr>
						</thead>
						<tbody>
							
							<%
								List stus = (List)request.getAttribute("stus");
								for(int i=0;i<stus.size();i++){
									Student stu = (Student)stus.get(i);
							%>
								<tr>
									<td><%=stu.getSid() %></td>
									<td><%=stu.getSname() %></td>
									<td><%=stu.getAge() %></td>
									<td><%=stu.getSex() %></td>
									<td><%=stu.getPhone() %></td>
									<td><%=stu.getSchool() %></td>
									<td><%=stu.getGrade() %></td>
									<td><%=stu.getMajor() %></td>
									<td>
										<a href="student?action=toupdate&sid=<%=stu.getSid() %>" class="btn btn-info">修改</a>
										<a href="student?action=delete&sid=<%=stu.getSid() %>" class="btn btn-info">删除</a>
									</td>
								</tr>
							
							<%								
								}
							%>
							
						</tbody>
					</table>
				</div>
				
			</div>
			
			<%
				Integer cp = (Integer)request.getAttribute("cp");
			    Integer count =  (Integer)request.getAttribute("count");
			    Integer total =  (Integer)request.getAttribute("total");
			   	
			    Enumeration<String> enumeration = request.getParameterNames();//sid 
			    StringBuffer sb = new StringBuffer();
			    while(enumeration.hasMoreElements()){
			    	String name = enumeration.nextElement();
			    	if(!name.equals("cp")){
			    		sb.append("&").append(name).append("=").append(request.getParameter(name));
			    	}
			    	//&action=query&sid=2017&sname=lisi
			    }
			%>
			<div style='text-align:center;'>
				<%if(cp<=1){%>
					<a class='btn btn-info' disabled >首页</a>
					<a class='btn btn-info' disabled >上一页</a>
				<%}else{ %>
					<a class='btn btn-info'  href="student?cp=1<%=sb.toString() %>">首页</a>
					<a class='btn btn-info'  href="student?cp=<%=cp-1%><%=sb.toString() %>">上一页</a>
				<%} %>
				<h2 style='display:inline;'>[<%=cp %>/<%=total %>]</h2>
				<h2 style='display:inline;'>[<%=count %>]</h2>
				<%if(cp>=total){%>
					<a class='btn btn-info' disabled>下一页</a>
					<a class='btn btn-info' disabled>尾页</a>
				<%}else{ %>
					<a class='btn btn-info'  href="student?cp=<%=cp+1%><%=sb.toString() %>">下一页</a>
					<a class='btn btn-info'  href="student?cp=<%=total %><%=sb.toString() %>">尾页</a>
				<%} %>
				<input type='text' class='form-control' style='display:inline;width:60px;' value=''/>
				<a class='btn btn-info' href='javascript:void(0);' 
				onclick='location.href="student?cp="+this.previousElementSibling.value+"<%=sb.toString() %>"'>GO</a>
			</div>
			
			<%@include file="footer.jsp" %>
		</div>
		
	</body>
</html>
